#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename T>void read(T &x){
    x=0;int f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^48);
    x*=f;
}
const int maxn=1e5+10;
int n,T;
ll ans;
int a[maxn],b[100];
void solve(){
    b[1]++;
    for(int i=1;i<=n;i++){
        if(b[i]>1){
            b[i]=0;
            b[i+1]++;
        }
    }
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    read(T);
    while(T--){
        read(n);
        ans=0;
        for(int i=1;i<=n+1;i++) b[i]=0;
        for(int i=1;i<=n;i++) read(a[i]);
        while(b[n+1]==0){
            int red=0,blue=0;
            ll cnt=0;
            for(int i=1;i<=n;i++){
                if(b[i]==0){
                    if(a[i]==a[red]) cnt+=(ll)a[i];
                    red=i;
                }else{
                    if(a[i]==a[blue]) cnt+=(ll)a[i];
                    blue=i;
                }
                ans=max(ans,cnt);
            }
            solve();
        }
        printf("%lld\n",ans);
    }
    return 0;
}
